#pragma once

#include <string>
#include <list>
#include <map>
#include <mymutex.hxx>
#include "shtunelmanager.hxx"

using namespace std;

#define CURL_ERROR_SIZE 256

class FileLog;
typedef void CURL;

class SHTunel
{
public:
	SHTunel(const string& host, const string& method, FileLog* filelog);
	~SHTunel();

	CURL* GetCurl(void) const;
	const char* GetCurlError(void) const;

protected:
	friend class SHTunelManager;
	friend class SHTunelManager::SHTunelListUnit;

	bool KeepAlive(void);
	bool SetInUse(void);
	bool Reset(void);

	bool Init(void);
	bool SendHItem(const string& hItem);
	string NextHItem(void);
	bool SendLeftHeaders(void);

	static const int VL = 120;
	static const int SendInterval = 10;

	const string host;
	const string method;

	CURL* curlRaw;
	Mutex curlRawInUse;

	char curlError[CURL_ERROR_SIZE];
	bool inUse;
	std::map<string, string> generalHeaders;
	std::map<string, string>::iterator iterGeneralHeaders;

	FileLog* _filelog;
};